/**
 *
 */
package com.googlecode.bip.entity;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Bean for a localized Topic
 *
 * @author Claude CHOISNET
 */
public class Topic
    implements  Serializable,
                ITopic,
                Comparable<Topic>
{
    private static final long serialVersionUID = 1L;

    private int idtopic;
    private String idlocal;
    private String name;
    private String description;
    private int parentidtopic;
    private int order;
    private int isactive;

    /**
     * Create a NOT initialized Topic (but define as active)
     */
    public Topic()
    {
        this.isactive = 1;
    }

    /**
     * Create a shadow copy of giving Topic
     *
     * @param o Topic to clone
     */
    public Topic( final Topic o )
    {
        this.idtopic        = o.idtopic;
        this.idlocal        = o.idlocal;
        this.name           = o.name;
        this.description    = o.description;
        this.parentidtopic  = o.parentidtopic;
        this.order          = o.order;
        this.isactive       = o.isactive;
    }

    @Override
    public int compareTo( final Topic o )
    {
        if( o == null ) {
            return Integer.MIN_VALUE;
            }
        if( this == o ) {
            return 0;
            }

        int cmp = this.idtopic - o.idtopic;
        if( cmp != 0 ) { return cmp; }

        cmp = StringComparator.compareString( this.idlocal, o.idlocal );
        if( cmp != 0 ) { return cmp; }

        cmp = StringComparator.compareString( this.name, o.name );
        if( cmp != 0 ) { return cmp; }

        cmp = StringComparator.compareString( this.description, o.description );
        if( cmp != 0 ) { return cmp; }

        cmp = this.parentidtopic - o.parentidtopic;
        if( cmp != 0 ) { return cmp; }

        cmp = this.order - o.order;
        if( cmp != 0 ) { return cmp; }

        cmp = this.isactive - o.isactive;

        return cmp;
    }

    /**
     * Initialize Topic from a ResultSet
     * @param rSet Valid ResultSet for a Topic
     * @return this Topic
     * @throws SQLException
     */
    public ITopic set( final ResultSet rSet ) throws SQLException
    {
        idtopic         = rSet.getInt( "idtopic" );
        idlocal         = rSet.getString( "idlocal" );
        name            = rSet.getString( "topicname" );
        description     = rSet.getString( "topicdescription" );
        parentidtopic   = rSet.getInt( "parentidtopic" );
        order           = rSet.getInt( "order" );
        isactive        = rSet.getInt( "isactive" );

        return this;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#getIdTopic()
     */
    @Override
    public int getIdTopic()
    {
        return idtopic;
    }

    /**
     *
     * @param idtopic the idtopic to set
     */
    public void setIdTopic( int idtopic )
    {
        this.idtopic = idtopic;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#getIdlocal()
     */
    @Override
    public String getIdLocal()
    {
        return idlocal;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#setIdlocal(java.lang.String)
     */
    @Override
    public void setIdLocal( String idlocal )
    {
        this.idlocal = idlocal;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#getName()
     */
    @Override
    public String getName()
    {
        return name;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#setName(java.lang.String)
     */
    @Override
    public void setName( String name )
    {
        this.name = name;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#getDescription()
     */
    @Override
    public String getDescription()
    {
        return description;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#setDescription(java.lang.String)
     */
    @Override
    public void setDescription( String description )
    {
        this.description = description;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#getParentIdTopic()
     */
    @Override
    public int getParentIdTopic()
    {
        return parentidtopic;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#setParentIdTopic(int)
     */
    @Override
    public void setParentIdTopic( int parentidtopic )
    {
        this.parentidtopic = parentidtopic;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#getOrder()
     */
    @Override
    public int getOrder()
    {
        return order;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#setOrder(int)
     */
    @Override
    public void setOrder( int order )
    {
        this.order = order;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#getIsActive()
     */
    @Override
    public int getIsActive()
    {
        return isactive;
    }

    /* (non-Javadoc)
     * @see com.googlecode.bip.entity.ITopic#setIsActive(int)
     */
    @Override
    public void setIsActive( int isactive )
    {
        this.isactive = isactive;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();

        builder.append("Topic [idtopic=").append(idtopic)
               .append(", idlocal=").append(idlocal)
               .append(", name=").append(name)
               .append(", description=").append(description)
               .append(", parentidtopic=").append(parentidtopic)
               .append(", order=").append(order)
               .append(", isactive=").append(isactive)
               .append("]");

        return builder.toString();
    }
}
